Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add classes output switch to Tailwind CLI #14373

Closed

Conversation

bopm
Copy link

@bopm bopm commented Sep 9, 2024

Introduce a new switch --classes-output to the Tailwind CLI build command to output only detected classes.

  • src/cli/index.js
    • Add a new switch --classes-output to the build command.
  • src/lib/expandTailwindAtRules.js
    • Update the expandTailwindAtRules function to handle the --classes-output switch.
    • Add logic to output only the detected classes when the switch is enabled.
  • tests/variants.test.js
    • Add tests to verify the functionality of the --classes-output switch.
    • Include test cases for different scenarios with the new switch.

Introduce a new switch `--classes-output` to the Tailwind CLI build command to output only detected classes.

* **src/cli/index.js**
  - Add a new switch `--classes-output` to the build command.
* **src/lib/expandTailwindAtRules.js**
  - Update the `expandTailwindAtRules` function to handle the `--classes-output` switch.
  - Add logic to output only the detected classes when the switch is enabled.
* **tests/variants.test.js**
  - Add tests to verify the functionality of the `--classes-output` switch.
  - Include test cases for different scenarios with the new switch.
@philipp-spiess
Copy link
Member

Hey @bopm! Thanks for the PR and sorry for not getting back to you earlier (we're currently crunching on Tailwind v4 work to get it ready for a beta release)

Do you have some context on why you need this feature? Are you able to get a similar output by parsing the generated CSS file for class names?

@bopm
Copy link
Author

bopm commented Nov 11, 2024

@philipp-spiess parsing generated CSS is not as straightforward as saving it while we have it. Here is how much I need to do in completely unrelated to Tailwind or CSS project.

So generally speaking, my problem is that as an author of Rails gem which uses Tailwind, I have to find a way to export my project classes (obviously generated with specific configuration that may not be the same as in the parent project) and then inject them into the parent application. And that may happen for the multiple libraries at the same time. So I discussed with @adamwathan how this can be achieved and this approach came up as a result of that discussion. I am still not sure if it's the best approach, but at least compute it's least wasteful. We save classes when we have them and reuse them on compilations of the host app.

@bopm bopm requested a review from a team as a code owner November 11, 2024 15:45
@RobinMalfait RobinMalfait changed the base branch from main to v3 January 27, 2025 11:17
@RobinMalfait
Copy link
Member

Hey!

Now that v4 is out, it's unlikely that we are going to add new features to v3. That said, I am also not sure what the best approach is to add this behavior to v4 and if there is a better solution to your problem.

I'm also curious what the actual problem is you are trying to solve:

So generally speaking, my problem is that as an author of Rails gem which uses Tailwind, I have to find a way to export my project classes (obviously generated with specific configuration that may not be the same as in the parent project) and then inject them into the parent application.

I'm currently not really sure why you need to export classes and inject them into the parent application. I wonder if there is a way to use an @import that imports a CSS file that has custom @source directives in it. More info: https://tailwindcss.com/docs/functions-and-directives#source-directive

Either way, it's still something I'm interested in to learn more about, but going to close this PR for now, but happy to talk about this in a discussion for v4.

Thanks again!

@bopm
Copy link
Author

bopm commented Jan 29, 2025

@RobinMalfait thanks for pointing me towards that, it allowed me to approach to a convention based solution for Rails. I just opened PR towards tailwindcss-rails with it.

I am still a bit concerned about chicken v.s. egg flow of these includes (right now I am building list of includes starting from libs, and last one is host app CSS) in terms of theming and other stuff like that. But for now I rely on giving users ability to override library CSS in host application to resolve it. I happy to hear any thoughts on right approach with that.

@bopm bopm deleted the bopm/add-classes-output-switch branch January 29, 2025 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants